#include<bits/stdc++.h>
using namespace std;

const int N  = 100010;
int n,T;
int a[N],ne[N],e[N],c[N],ans[N];

void ch(int a)
{
    if(a == 0) a = 1;
    else a = 0;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> T;
    for(int i = 1;i <= T;i ++)
    {
        cin >> n;
        for(int j = 1;j <= n;j ++) cin >> a[j];
        for(int j = 1;j <= n;j ++) e[j] = 1;
        for(int j = 2;j <= n;j ++)
        {
            if(a[j] == a[j - 1])
            {
                ne[j] = ne[j - 1];
            }
            else if(a[j] == a[j - 2])
                {
                    ne[j] = ne[j - 2];
                    if(ne[j] == ne[j - 1]) ch(ne[j - 1]);
                }
        }
        for(int j = 2;j <= n;j ++)
        {

            if(ne[j] == ne[j - 1] && a[j] == a[j - 1]) c[j] = a[j];
            else
            {
                if(ne[j] == ne[j - 2] && a[j] == a[j - 2]) c[j] = a[j];
                    else if(ne[j] == ne[j - 3] && a[j] == a[j - 3] && ne[j - 2]==ne[j - 1]) c[j] = a[j];
                                else c[j] = 0;
            }
        }
        for(int j = 1;j <= n;j ++) ans[i] += c[j];
    }
    for(int i = 1;i <= T;i ++) cout << ans[i] << "\n";
    return 0;
}
